function Mover(textModel){
    this.$textModel = textModel;
}

var _MOVE_LEFT = 1;
var _MOVE_RIGHT = 2;
var _MOVE_HOME = 3;
var _MOVE_END = 4;

Mover.prototype = {
    move: function (kind, offset){
        switch (kind) {
        case _MOVE_LEFT:
            return this.moveLeft(offset);
        case _MOVE_RIGHT:
            return this.moveRight(offset);
        case _MOVE_HOME:
            return this.moveHome();
        case _MOVE_END:
            return this.moveEnd();
        }
    },
    moveHome: function (){
        return 0;
    },
    moveEnd: function (){
        var textModel = this.$textModel;
        return textModel.getLength();
    },
    movePageUp: function (){

    },
    movePageDown: function (){

    },
    moveLeft: function (offset){
        if (offset == 0) {
            return 0;
        }
        var textModel = this.$textModel;
        var lineIndex = textModel.getLineIndex(offset);
        if (offset == textModel.getLineStartOffset(lineIndex)) {
            return textModel.getLineEndOffset(lineIndex - 1);
        }
        return offset - 1;
    },
    moveRight: function (offset){
        var textModel = this.$textModel;
        if (offset == textModel.getLength()) {
            return textModel.getLength();
        }
        var lineIndex = textModel.getLineIndex(offset);
        if (offset == textModel.getLineEndOffset(lineIndex)) {
            return textModel.getLineStartOffset(lineIndex + 1);
        }
        return offset + 1;
    }
};
